package org.jeecg.modules.demo.jxcx.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.demo.jxcx.Utils.R;
import org.jeecg.modules.demo.jxcx.Utils.RandomUtil;
import org.jeecg.modules.demo.jxcx.mapper.JxcXxfbMapper;
import org.jeecg.modules.demo.jxcx.po.JxcXxfb;
import org.jeecg.modules.demo.jxcx.service.JxcXxfbService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
* @author Administrator
* @description 针对表【jxc_xxfb】的数据库操作Service实现
* @createDate 2024-09-22 20:37:35
*/
@Service
public class JxcXxfbServiceImpl extends ServiceImpl<JxcXxfbMapper, JxcXxfb>
implements JxcXxfbService{

    private static Logger logger = LoggerFactory.getLogger(JxcXxfbServiceImpl.class);
    @Override
    public List<JxcXxfb> queryall() {
        return baseMapper.queryall();
    }

    @Override
    public R add(JxcXxfb jxcXxfb) {
        LocalDateTime now = LocalDateTime.now();
        // 定义日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        String formattedDateTime = now.format(formatter);
        String only1 = RandomUtil.generateRandomString();
        String id = now.format(formatter2) + only1;
        jxcXxfb.setId(id);
        jxcXxfb.setCreateTime(formattedDateTime);
        logger.info("添加信息："+jxcXxfb);
        return new R().ok(save(jxcXxfb));
    }
}
